#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;

int n, x[ 201 ], y[ 201 ], r[ 201 ];
vector<int> li[ 201 ];

void init( )
{
    int i, j;
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
    {
        li[ i ].clear( );
        scanf("%d%d%d", &x[ i ], &y[ i ], &r[ i ]);
    }
    for ( i = 0; i < n; i++ )
        for ( j = i + 1; j < n; j++ )
            if ( ( x[ i ] - x[ j ] ) * ( x[ i ] - x[ j ] ) + ( y[ i ] - y[ j ] ) * ( y[ i ] - y[ j ] )
                <= ( r[ i ] + r[ j ] ) * ( r[ i ] + r[ j ] ) )
            {
                li[ i ].push_back( j );
                li[ j ].push_back( i );
            }
}

void spfa( int *d, int st )
{
    int i, p;
    queue<int> q;
    for ( i = 0; i < n; i++ )
        d[ i ] = 100000000;
    d[ st ] = 0;
    q.push( st );
    while ( !q.empty( ) )
    {
        p = q.front( ); q.pop( );
        for ( i = 0; i < li[ p ].size( ); i++ )
            if ( d[ li[ p ][ i ] ] > d[ p ] + 1 )
            {
                d[ li[ p ][ i ] ] = d[ p ] + 1;
                q.push( li[ p ][ i ] );
            }
    }
}

void work( )
{
    int i, j, k, minn = 100000000, d[ 3 ][ 201 ];
    spfa( d[ 0 ], 0 );
    spfa( d[ 1 ], 1 );
    spfa( d[ 2 ], 2 );
    for ( i = 0; i < n; i++ )
        if ( minn > d[ 0 ][ i ] + d[ 1 ][ i ] + d[ 2 ][ i ] )
            minn = d[ 0 ][ i ] + d[ 1 ][ i ] + d[ 2 ][ i ];
    if ( minn == 100000000 )
        puts("-1");
    else
        printf("%d\n", n - minn - 1);
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
